package khl.ooo.domain.cursus;
import java.util.TreeSet;

import khl.ooo.domain.Lesmoment;
import khl.ooo.domain.vak.Vak;

public class Cursus implements Cloneable, Comparable<Cursus> {
	private int maximumAantalStudenten;
	private String docent;
	private Vak cursusvak;
	private TreeSet<Lesmoment> lesmomenten;
	
	
	CursusState StateOpen;
	CursusState StateAfgesloten;
	CursusState StateGeannuleerd;
	CursusState Vol;
	
	CursusState state=StateAfgesloten;
	
	public void setState(CursusState staat)
	{
		this.state=staat;
	}
	public Cursus (int max, String docent, TreeSet<Lesmoment> lesmomenten, Vak vak){
		this.setMaximumAantalStudenten(max);
		this.setDocent(docent);
		this.setLesmomenten(lesmomenten);
		this.setVak(vak);
		this.setState(StateOpen);
	}
	
	public void setLesmomenten(TreeSet<Lesmoment> momenten) {
		if(momenten != null) {
			this.lesmomenten = momenten;
		} else {
			throw new IllegalArgumentException();
		}
	}
	public TreeSet<Lesmoment> getLesmomenten() {
		return this.lesmomenten;
	}
	
	public void setVak(Vak vak) {
		if(vak != null && vak instanceof Vak) {this.cursusvak = vak;} 
		else {throw new IllegalArgumentException();}
	}
	
	public Vak getVak() {
		return this.cursusvak;
	}
	
	public void VoegLesmomentToe(Lesmoment moment)
	{
		state.VoegLesmomentToe(moment);
	}
	
	public void setMaximumAantalStudenten(int max){ //liever geen afkortingen
		if (max>0)
			{this.maximumAantalStudenten=max;}
		else
			{throw new IllegalArgumentException();}	
		}
	public int getMaximumAantalStudenten()
		{return this.maximumAantalStudenten;}
	public void setDocent(String d){
		if (d instanceof String && d != null && d != "")
			{this.docent=d;}
		else
			{throw new IllegalArgumentException();}
	}
	public String getDocent() {
		return this.docent;
	}
	
	public void addLesmoment(Lesmoment les) {
		if(les != null && les instanceof Lesmoment) {
			if(this.lesmomenten.contains(les))
				throw new IllegalArgumentException();
			else
				this.lesmomenten.add(les);
		} else {
			throw new IllegalArgumentException();
		}
	}
	
	public boolean equals(Cursus c) {
		if(c != null && c instanceof Cursus) {
			return c.getVak().equals(this.getVak()) && c.getDocent().equals(this.getDocent());
		} else {
			return false;
		}
	}
	
	public String toString() {
		/* "Maximum aantal studenten: " + this.geldigemax + "\n "
		+ "Docent: " + this.docent + "\n" + "Vak: " + this.vak + "\n"
		+ lesmoment1, cursus.toString()); */
		String output = "";
		output += "Maximum aantal studenten: " + this.getMaximumAantalStudenten() + "\n" +
			"Docent: " + this.getDocent() + "\n" +
			"Vak: " + this.getVak() + "\n" +
			this.getLesmomenten().first();
		return output;
	}
	 public Object clone() {
		    Object o = null;
		    try {
		      o = super.clone();
		    } catch (CloneNotSupportedException e){}
		    return o;
		  }
	@Override
	public int compareTo(Cursus o) {
		int retour=-1;
		if(
			this.getDocent() == o.getDocent() 
			&& this.getLesmomenten() == o.getLesmomenten() 
			&& this.getMaximumAantalStudenten() == o.getMaximumAantalStudenten()
			&& this.getVak().equals(o.getVak())
			)
		{retour=0;}
		
		return retour;
	}
}
